// eventBus.js
class EventBus {
  constructor () {
    this.handlers = {}
  }

  on (event, handler) {
    if (!this.handlers[event]) {
      this.handlers[event] = []
    }
    this.handlers[event].push(handler)
  }

  emit (event, ...args) {
    const handlers = this.handlers[event]
    if (handlers) {
      handlers.forEach((handler) => {
        handler(...args)
      })
    }
  }

  off (event, handler) {
    const handlers = this.handlers[event]
    if (handlers) {
      if (handler) {
        this.handlers[event] = handlers.filter(h => h !== handler)
      } else {
        this.handlers[event] = []
      }
    }
  }
}

export default new EventBus()
